package com.music.controller;

import com.github.pagehelper.PageInfo;
import com.music.dto.Result;
import com.music.entity.Mv;
import com.music.service.MvService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname MvController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2022/7/4 13:29
 * @Created by Administrator
 */
@RestController
@RequestMapping("/mv")
@Slf4j
public class MvController {

    @Autowired
    private MvService mvService;

    @GetMapping
    public Result getMvByCondition(@RequestParam Integer pageNum, @RequestParam Integer pageSize, Integer districtId, Integer mvTypeId, @RequestParam String rank) {
        Result result = new Result();
        PageInfo<Mv> pageInfo = mvService.getMvByCondition(pageNum, pageSize, districtId, mvTypeId, rank);
        if (!pageInfo.getList().isEmpty()) {
            result.ok(pageInfo);
        } else {
            result.fail(0, "没有相关数据");
        }
        return result;
    }

    @GetMapping("/getOne")
    public Result getMvByCondition(@RequestParam String mvId) {
        Result result = new Result();
        Mv mv = mvService.getMvByMvId(mvId);
        if (mv != null) {
            result.ok(mv);
        } else {
            result.fail(0, "没有相关数据");
        }
        return result;
    }
    @GetMapping("/all")
    public Result dogetMvList(Integer districtId){
        Result result=new Result();
        List<Mv> list=mvService.getMvList(districtId);
        if(!list.isEmpty()){
            result.ok(list);
        }else{
            result.fail(0,"没有相关数据");
        }
        return result;
    }
}
